package com.szholly.pro.watergas_server.ps.android.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import com.szholly.pro.watergas_server.common.data.DataUtil;
import com.szholly.utils.util.JSONUtils;
import com.szholly.data.general.GlobalParameter;
import com.szholly.data.general.RowBase;

@Service
public class AndroidSupplyManager {

	public String saveLocaleCheck(String saveData, String listMap) {
		return null;
	}

	/**
	 * 根据id获取供水耗材字典项
	 * 
	 * @param S_DOMAINNAME
	 * @return
	 */
	public String getdomainByID(String S_DOMAINNAME) {
		String sql = "select S_DOMAINCODE,S_DOMAINNAME,s_domaincaption,PY_PREFIX,s_id,s_pid ,TYPE from DATA_DEFULATDOMAIN where 1=1 ";// and
																																		// s_ischild='1'
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		if (S_DOMAINNAME != null
				&& !S_DOMAINNAME.equals("")) {
			sql += " and S_DOMAINNAME =@S_DOMAINNAME";
			parms.add(new GlobalParameter("S_DOMAINNAME", S_DOMAINNAME));
		}
		sql += " and type is not null order by i_order";
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null
				&& rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "";
		}
	}

	public String getSupplyLocationParamData() {
		String sql = "SELECT t1.s_domaincaption,t1.s_domaincode ,t.SITE_ID from BC_SITE_POLL t\n"
				+ "        left join data_defulatdomain t1 on t.name = t1.S_DOMAINCODE\n"
				+ "\t\t\t\twhere t1.S_DOMAINNAME like '%供水参数%' and length(t.SITE_ID) <4";
		// s_ischild='1'
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null
				&& rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "[]";
		}
	}

	public String getSupplyAbnormalReason() {
		String sql = "select t.s_domaincode,t.s_domaincaption as phenomenon,t1.s_domaincaption as reason from data_defulatdomain t\n" +
						"       left join data_defulatdomain t1 on t1.type=t.s_domaincode and t1.s_domainname='故障原因'\n" + 
						"        where t.s_domainname = '供水异常故障项' and t.s_pid is not null\n" + 
						"        order by t.s_domaincaption asc";


		// s_ischild='1'
		List<GlobalParameter> parms = new ArrayList<GlobalParameter>();
		List<RowBase> rows = DataUtil.getSelectRows(sql, parms);
		if (rows != null
				&& rows.size() >= 0) {
			return JSONUtils.toJSONString(rows);
		} else {
			return "[]";
		}
	}
}
